package com.siwei.mes.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.entity.AssociationStorage;
import com.siwei.mes.mapper.AssociationStorageMapper;
import com.siwei.mes.service.AssociationStorageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

/**
 * 协会信息存储(AssociationStorage)表服务实现类
 *
 * @author linzi
 * @since 2024-07-31 09:00:11
 */
@Service
public class AssociationStorageServiceImpl implements AssociationStorageService {
    @Resource
    private AssociationStorageMapper associationStorageMapper;

    @Override
    public Long create(AssociationStorage entity) {
        associationStorageMapper.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public void update(AssociationStorage entity) {
        AssociationStorage associationStorage = associationStorageMapper.selectByPrimaryKey(entity.getId());
        assertTrue(associationStorage == null, "协会信息存储信息不存在");
        associationStorageMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void delete(Long id) {
        AssociationStorage associationStorage = associationStorageMapper.selectByPrimaryKey(id);
        assertTrue(associationStorage == null, "协会信息存储信息不存在");
        associationStorageMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<AssociationStorage> getPage(PageQuery<AssociationStorage, AssociationStorage> query) {
        AssociationStorage searchParam = query.getParams();
        return PageHelper.startPage(query.getPageNum(), query.getPageSize())
                .doSelectPageInfo(() -> associationStorageMapper.getList(searchParam));
    }

    @Override
    public AssociationStorage loadById(Long id) {
        return associationStorageMapper.loadById(id);
    }

    @Override
    public List<AssociationStorage> getAll(AssociationStorage entity) {
        return associationStorageMapper.getList(entity);
    }
}
